<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      border-top: 1px solid transparent;
    }

    ul,
    li {
      list-style: none;
      /* 移除列表的标记（如圆点或序号） */
      padding: unset;
      margin: unset;
    }

    .view {
      width: 400px;
      height: 200px;
      border: 1px solid #000;
      margin: 200px auto 0px;
      /* position: relative; */
      overflow-y: hidden;
    }

    .img-list {
      display: flex;
      width: calc(220px * 350);
      /* position: absolute;
      top: 50px; */
    }

    .img-list.icon {
      /* transition: all 5s cubic-bezier(0, .56, .09, .99);  */
      animation: goto 5s cubic-bezier(0, .56, .09, .99) forwards;
    }

    @keyframes goto {
      0% {
        transform: translateX(0px);
      }

      100% {
        transform: translateX(-67000px);
      }
    }

    .img-item {
      height: 100px;
      width: 200px;
      margin-right: 20px;
      text-align: center;
      line-height: 100px;
      font-size: 24px;
    }

    .img-item:nth-last-child(1) {
      margin-right: unset;
    }

    .img-item:nth-child(2n) {
      background-color: aqua;
    }

    .img-item:nth-child(2n + 1) {
      background-color: pink;
    }

    .start-btn {
      position: absolute;
      left: 50%;
      top: 100px;
      transform: translateX(-50%);
      cursor: pointer;
    }
  </style>
</head>

<body>
  <div style="text-align: center;color: red;font-size: 24px;">抽奖结束后刷新下页面</div>
  <button onClick="startBtnFn()" class="start-btn">开始抽奖</button>
  <div class="view">
    <ul class="img-list">
      <li class="img-item">1</li>
      <li class="img-item">2</li>
    </ul>
  </div>
  <script>
    const view = document.querySelector(".view");
    const imgList = document.querySelector(".img-list");
    let str = ``
    for (let i = 1; i < 350; i++) {
      str += `<li class="img-item">${i}</li>`
    }
    imgList.innerHTML = str;

    let requestID = NaN;
    let timer = NaN;
    let shiftingX = 0;
    const supportAnimationFrame = typeof requestAnimationFrame === 'function';

    function raffleAnimation() {
      if (shiftingX + view.offsetWidth >= imgList.offsetWidth) {
        shiftingX = 0;
      }
      ++shiftingX;
      imgList.style.transform = `translateX(-${shiftingX}px)`;

      if (supportAnimationFrame) {
        requestID = requestAnimationFrame(raffleAnimation);
      }
    }


    function resetLotteryStatus() {
      if (supportAnimationFrame) {
        requestID && window.cancelAnimationFrame(requestID);
        requestID = requestAnimationFrame(raffleAnimation);
      } else {
        timer && clearInterval(timer);
        timer = window.setInterval(() => {
          raffleAnimation();
        }, 1 / 60);
      }
    }
    // resetLotteryStatus();
    async function startBtnFn() {
      console.log("开始抽奖");
      requestID && window.cancelAnimationFrame(requestID);
      timer && clearInterval(timer);
      // imgList.style.transform = 'translateX(0px)';
      const doAnimate = () => {
        if (!imgList) {
          return;
        }
        imgList.classList.add('icon');
        imgList.style.transform = `translateX(-${67000}px)`;
      };
      if (typeof requestAnimationFrame === 'function') {
        requestAnimationFrame(doAnimate);
      } else {
        await window.setTimeout(() => { }, 10);
        doAnimate();
      }
    }
  </script>
</body>

</html>